font chooser dialog: Improve sensitivity handling
authorMatthias Clasen <mclasen@redhat.com>
Wed, 3 Jan 2018 19:04:50 +0000 (14:04 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 3 Jan 2018 19:05:33 +0000 (14:05 -0500)
We should not tie the sensitivity of the select button
to the tweak action, since there may be fonts which are
selectable, but not tweakable.

Instead, enable the select button when a font is selected,
as it should be.

gtk/gtkfontchooserdialog.c

index 45dc87d14de5267c0b7fce81532a999b6b011d72..dca48115541b29a15796a48377dc31c4fa9a7dbb 100644 (file)
@@ -208,6 +208,21 @@ gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, font_activated_cb);
 }
 
+static void
+update_button (GtkFontChooserDialog *dialog)
+{
+  GtkFontChooserDialogPrivate *priv = dialog->priv;
+  PangoFontDescription *desc;
+
+  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (priv->fontchooser));
+
+  gtk_widget_set_sensitive (priv->select_button, desc != NULL);
+
+  if (desc)
+    pango_font_description_free (desc);
+}
+
+
 static void
 gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag)
 {
@@ -222,11 +237,9 @@ gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag)
   _gtk_font_chooser_set_delegate (GTK_FONT_CHOOSER (fontchooserdiag),
                                   GTK_FONT_CHOOSER (priv->fontchooser));
 
-  g_object_bind_property (gtk_font_chooser_widget_get_tweak_action (priv->fontchooser),
-                          "enabled",
-                          priv->select_button,
-                          "sensitive",
-                          G_BINDING_SYNC_CREATE);
+  g_signal_connect_swapped (priv->fontchooser, "notify::font-desc",
+                            G_CALLBACK (update_button), fontchooserdiag);
+  update_button (fontchooserdiag);
 }
 
 /**